var db = require('../utils/db');

class UserModel {

  constructor() {
    this.model = db.model('users', {
      username: String,
      password: String,
      sex:Number,
      age:Number,
      birthday:String,
      address:String
    })
  }

  save(data) {
    let model = new this.model(data)
    return model.save();
  }

  findOne(data) {
    return this.model.findOne(data);
  }

  /**
   * 用户列表查询
   * @param {*} searchParams 查询条件
   * @param {*} pagesize 每页条数
   * @param {*} pageno 第几页
   */
  query(searchParams, pagesize, pageno) {
    console.log(searchParams, pagesize, pageno)
    return this.model.find(searchParams)
      .limit(pagesize * 1)
      .skip((pageno) * pagesize)


  }

  count(params) {
    return this.model.find(params).count()
  }

  remove(_ids) {
    return this.model.deleteMany({ _id: { $in: _ids } })
  }

}

module.exports = new UserModel();